{extend  name="manage@public/layout" /}
{block name="style"}
<link href="/static/css/plugins/chosen/chosen.css" rel="stylesheet">
<link href="/static/css/style.min.css" rel="stylesheet">
<style>
.chosen-container {
    width:287px !important;
}
    
</style>
 {/block}
 {block name="content"}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5 style="margin:-5px 5px 0px !important;">
                            <button onClick="modaldemo()" style="padding:4px;margin-bottom:0 !important" type="button" class="btn btn-primary btn-xs">添加白名单</button>
                        </h5>
                        <div class="ibox-tools">
                            <a class="collapse-link" onclick="location.replace(location.href);">
                                <i class="fa fa-refresh"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="table-responsive">
                            <form action="" method="get">
                                <div class="col-sm-2 col-sm-on">
                                    <input type="text" value="{notempty name="data['keyword']"}{$data['keyword']|trim}{/notempty}" name="keyword" placeholder="商户号/商户名称" class="input-sm form-control">
                                </div>
                                <div class="col-sm-1 col-sm-botton" >
                                    <div class="input-group">
                                        <button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                            </form>
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th style="width:100px;">ID</th>
                                        <th style="width:100px;">商户号</th>
                                        <th >商户名称</th>
                                        <th >IP</th>
                                        <th>备注</th>
                                        <th style="width:140px;">创建时间</th>
                                        <th style="width:145px;">操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {volist name="list" id="vo"}
                                    <tr>
                                        <td>{$vo.id}</td>
                                        <td>{$vo.mch_id}</td>
                                        <td>{:\\app\\model\\Mch::getMch($vo.mch_id)}</td>
                                        <td>{$vo.white_ip}</td>
                                        <td>{$vo.remark|default=''}</td>
                                        <td>{$vo.create_time}</td>
                                        <td>
                                            <button onClick="with_ip_edit('{:url('/manage/with_ip_edit',['pid'=>$vo.id])}')" style="border: 1px solid #05b52b;color: #05b52b;"type="button" data-id="{$vo.id}" class="btn btn-sm btn-white"><i class="fa fa-edit"></i>&nbsp;编辑</button>
                                            <button style="color:red;border:1px solid red;" type="button" data-id="{$vo.id}" class="btn btn-sm btn-white-ip_del btn-white"><i class="fa fa-trash"></i>&nbsp;删除</button>
                                        </td>
                                    </tr>
                                    {/volist}
                                </tbody>
                            </table>
                            <div style="float:right;" class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                                <ul class="pagination">
                                    {$page}
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div> 
    <!-- 弹框 --->
    <div id="modal-demo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
        <div class="modal-dialog">
            <div class="modal-content radius">
                <div class="modal-header">
                    <h3 class="modal-title">添加白名单</h3>
                    <a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">商户</label>
                        <div class="col-sm-7">
                            <select id="mch" class="chosen-select form-control" style="width:350px;" tabindex="2">
                                <option value="0">请选择商户</option>
                                {volist name="mch" id="vo"}
                                <option value="{$vo.mch}" >{$vo.mch}[{$vo.mch_name}]</option>
                                
                                {/volist}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="hr-line-dashed" style="margin:0;"></div>
                <div style="height:145px;" class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">IP地址</label>
                        <div class="col-sm-7">
                            <textarea class="input-sm form-control" rows="4" cols="30" placeholder="多个IP用|隔开" id="white_ip" name="white_ip"></textarea>
                        </div>
                    </div>
                </div>
                <div class="hr-line-dashed" style="margin:0;"></div>
                <div style="height:145px;" class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">备注</label>
                        <div class="col-sm-7" id="select">
                            <textarea id="remark" class="input-sm form-control" rows="4" cols="30" placeholder="请输入内容" name="remark"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary btn-white-ip ">确定</button>
                    <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <!--  end --->
    {/block}
    {block name="script"}
<script src="/static/js/plugins/chosen/chosen.jquery.js"></script>
<script>
    function with_ip_edit(url){
        parent.layer.open({
            type: 2,
            title: '编辑',
            shadeClose: true,
            shade: 0.4,
            area: ['700px', '520px'],
            content: url,
            end:function(){
                window.location.href = "/manage/withdrawal_ip";
            },
        }); 
    }
    //模糊搜索
    $('.chosen-select').chosen({
        search_contains: true,
    });
    //打开弹框
    function modaldemo(){
        $("#modal-demo").modal('show');
    }
    //添加
    $(".btn-white-ip").click(function(){
        white_ip = $("#white_ip").val();
        remark   = $("#remark").val();
        mch   = $("#mch option:selected").val();
        $.post("/manage/withdrawal_ip_save",{type:1,white_ip:white_ip,mch_id:mch,remark:remark},function(result){
            parent.layer.msg(result.msg);
            setTimeout(function() {
                window.location.reload();
            }, 1000)
        })
    })
    //删除
    $(".btn-white-ip_del").click(function(){
        id = $(this).attr("data-id");
        $.post("/manage/withdrawal_ip_save",{type:2,pid:id},function(result){
            parent.layer.msg(result.msg);
            setTimeout(function() {
                window.location.reload();
            }, 1000)
        })
    })
</script>
    {/block}

